[Exporter.Prometheus] Fix OpenMetrics histograms#7221
Merged
martincostello merged 8 commits intoMay 5, 2026
Merged
Conversation
Omit histogram `_sum` and `_count` in OpenMetrics when negative bucket thresholds are present.
martincostello
commented
Apr 29, 2026
martincostello
commented
Apr 29, 2026
Update PR number.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #7221 +/- ##
==========================================
- Coverage 89.98% 89.92% -0.06%
==========================================
Files 272 272
Lines 13643 13649 +6
==========================================
- Hits 12276 12274 -2
- Misses 1367 1375 +8
Flags with carried forward coverage won't be shown. Click here to find out more.
|
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes OpenMetrics histogram serialization in the Prometheus exporters to comply with the OpenMetrics spec when explicit bucket boundaries include negative thresholds.
Changes:
- Detect negative histogram bucket bounds during serialization when OpenMetrics output is requested.
- Omit histogram
_sumand_countseries in OpenMetrics output when negative bucket thresholds are present. - Add a unit test validating
_sum/_countomission and update changelogs for both Prometheus exporters.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusSerializerTests.cs | Adds coverage ensuring OpenMetrics output omits _sum and _count when buckets include negative bounds. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/PrometheusSerializerExt.cs | Implements conditional suppression of _sum/_count for OpenMetrics histograms with negative bucket thresholds. |
| src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md | Documents the behavioral change in the HttpListener exporter changelog. |
| src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md | Documents the behavioral change in the AspNetCore exporter changelog (shared serializer implementation). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
4 tasks
Kielek
approved these changes
May 5, 2026
This was referenced Jun 10, 2026
Open
This was referenced Jun 12, 2026
Merged
Merged
intellitect-bot
pushed a commit
to IntelliTect/EssentialCSharp.Web
that referenced
this pull request
Jun 12, 2026
….0 (#1201) Updated [OpenTelemetry.Exporter.OpenTelemetryProtocol](https://github.com/open-telemetry/opentelemetry-dotnet) from 1.15.3 to 1.16.0. <details> <summary>Release notes</summary> _Sourced from [OpenTelemetry.Exporter.OpenTelemetryProtocol's releases](https://github.com/open-telemetry/opentelemetry-dotnet/releases)._ ## 1.16.0 For highlights and announcements pertaining to this release see: [Release Notes > 1.16.0](https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/RELEASENOTES.md#1160). The following changes are from the previous release [1.16.0-rc.1](https://github.com/open-telemetry/opentelemetry-dotnet/releases/tag/core-1.16.0-rc.1). * NuGet: [OpenTelemetry v1.16.0](https://www.nuget.org/packages/OpenTelemetry/1.16.0) No notable changes. See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.16.0/src/OpenTelemetry/CHANGELOG.md) for details. * NuGet: [OpenTelemetry.Api v1.16.0](https://www.nuget.org/packages/OpenTelemetry.Api/1.16.0) No notable changes. See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.16.0/src/OpenTelemetry.Api/CHANGELOG.md) for details. * NuGet: [OpenTelemetry.Api.ProviderBuilderExtensions v1.16.0](https://www.nuget.org/packages/OpenTelemetry.Api.ProviderBuilderExtensions/1.16.0) No notable changes. See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.16.0/src/OpenTelemetry.Api.ProviderBuilderExtensions/CHANGELOG.md) for details. * NuGet: [OpenTelemetry.Exporter.Console v1.16.0](https://www.nuget.org/packages/OpenTelemetry.Exporter.Console/1.16.0) No notable changes. See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.16.0/src/OpenTelemetry.Exporter.Console/CHANGELOG.md) for details. * NuGet: [OpenTelemetry.Exporter.InMemory v1.16.0](https://www.nuget.org/packages/OpenTelemetry.Exporter.InMemory/1.16.0) No notable changes. See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.16.0/src/OpenTelemetry.Exporter.InMemory/CHANGELOG.md) for details. * NuGet: [OpenTelemetry.Exporter.OpenTelemetryProtocol v1.16.0](https://www.nuget.org/packages/OpenTelemetry.Exporter.OpenTelemetryProtocol/1.16.0) No notable changes. See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.16.0/src/OpenTelemetry.Exporter.OpenTelemetryProtocol/CHANGELOG.md) for details. * NuGet: [OpenTelemetry.Exporter.Zipkin v1.16.0](https://www.nuget.org/packages/OpenTelemetry.Exporter.Zipkin/1.16.0) No notable changes. See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.16.0/src/OpenTelemetry.Exporter.Zipkin/CHANGELOG.md) for details. * NuGet: [OpenTelemetry.Extensions.Hosting v1.16.0](https://www.nuget.org/packages/OpenTelemetry.Extensions.Hosting/1.16.0) No notable changes. ... (truncated) ## 1.16.0-rc.1 The following changes are from the previous release [1.15.3](https://github.com/open-telemetry/opentelemetry-dotnet/releases/tag/core-1.15.3). * NuGet: [OpenTelemetry v1.16.0-rc.1](https://www.nuget.org/packages/OpenTelemetry/1.16.0-rc.1) * Stop validating View-provided metric stream `Name` against the instrument name syntax, per [spec clarification](open-telemetry/opentelemetry-specification#5094). ([#7300](open-telemetry/opentelemetry-dotnet#7300)) * Fix incorrect validation of `OTEL_BSP_*` and `OTEL_BLRP_*` environment variables. ([#7187](open-telemetry/opentelemetry-dotnet#7187)) * Fix observable instrument callbacks running once per reader instead of once per collection cycle. ([#7188](open-telemetry/opentelemetry-dotnet#7188)) * Added exception safety for user-supplied `ExemplarReservoir` implementations. Exceptions thrown from `Offer` are now caught and logged rather than propagating out of `Counter.Add`/`Histogram.Record`. ([#7277](open-telemetry/opentelemetry-dotnet#7277)) * Update `OpenTelemetrySdkEventSource` to support the W3C randomness flag. ([#7301](open-telemetry/opentelemetry-dotnet#7301)) * Added `ObservedTimestamp` property to `LogRecord`. ([#6979](open-telemetry/opentelemetry-dotnet#6979)) * **Breaking Change** Explicit histogram boundaries no longer allow more than 10 million values. ([#7165](open-telemetry/opentelemetry-dotnet#7165)) * Fixed a circular reference which could cause a `LoggerProvider` to fail to resolve when one of its dependencies depends on `ILogger` or `ILoggerFactory`. As part of this fix the `LoggerProvider` resolved from dependency injection is now created lazily when the first logger is created rather than when `ILoggerProvider` or `ILoggerFactory` is resolved. A consequence is that any invalid configuration now surfaces when the first log record is written instead of when the logging services are resolved. ([#7308](open-telemetry/opentelemetry-dotnet#7308)) See [CHANGELOG](https://github.com/open-telemetry/opentelemetry-dotnet/blob/core-1.16.0-rc.1/src/OpenTelemetry/CHANGELOG.md) for details. * NuGet: [OpenTelemetry.Api v1.16.0-rc.1](https://www.nuget.org/packages/OpenTelemetry.Api/1.16.0-rc.1) * **Experimental (pre-release builds only):** Add support for using environment variables as context propagation carriers. ([#7174](open-telemetry/opentelemetry-dotnet#7174)) * Fix `BaggagePropagator` to correctly follow Key and Value Encoding rules as per ... (truncated) ## 1.16.0-beta.1 The following changes are from the previous release [1.15.3-beta.1](https://github.com/open-telemetry/opentelemetry-dotnet/releases/tag/coreunstable-1.15.3-beta.1). * NuGet: [OpenTelemetry.Exporter.Prometheus.AspNetCore v1.16.0-beta.1](https://www.nuget.org/packages/OpenTelemetry.Exporter.Prometheus.AspNetCore/1.16.0-beta.1) * Fixed scrape response cache freshness using monotonic time so it is not affected by NTP system clock adjustments. ([#7253](open-telemetry/opentelemetry-dotnet#7253)) * **Breaking Change** Removed `DisableTimestamp` property from `PrometheusAspNetCoreOptions`. ([#7176](open-telemetry/opentelemetry-dotnet#7176)) * Fixed the serialization of `NaN`, `PositiveInfinity`, and `NegativeInfinity` values in Prometheus metrics to be compliant with the specification. ([#7179](open-telemetry/opentelemetry-dotnet#7179)) * Fixed loss of precision when serializing `double` and `float` values in Prometheus metrics to be compliant with the specification by using 17 significant digits to represent such values. ([#7179](open-telemetry/opentelemetry-dotnet#7179)) * Fix non-ASCII characters in metric names and unit strings not being sanitized correctly during Prometheus serialization. ([#7184](open-telemetry/opentelemetry-dotnet#7184)) * Fix case where reader tracking could be reset while readers were still active. ([#7190](open-telemetry/opentelemetry-dotnet#7190)) * Improve `Accept` header handling for format negotiation so OpenMetrics is selected correctly by considering whitespace and `q` weights. ([#7208](open-telemetry/opentelemetry-dotnet#7208)) * Emit OpenMetrics exemplars for counters and histogram buckets. ([#7222](open-telemetry/opentelemetry-dotnet#7222)) * Fix incorrect handling of untyped metrics when using OpenMetrics format. ([#7219](open-telemetry/opentelemetry-dotnet#7219)) * Fix Prometheus/OpenMetrics serialization to emit metric and label names containing `_` instead of dropping them and prefixing leading digits. Invalid characters are replaced with `_` instead of being dropped. ([#7209](open-telemetry/opentelemetry-dotnet#7209)) * Add `escaping=underscores` to the `Accept` header handling for content negotiation so OpenMetrics are handled correctly. ([#7209](open-telemetry/opentelemetry-dotnet#7209)) * Omit histogram `_sum` and `_count` in OpenMetrics when negative bucket thresholds are present. ([#7221](open-telemetry/opentelemetry-dotnet#7221)) ... (truncated) Commits viewable in [compare view](open-telemetry/opentelemetry-dotnet@core-1.15.3...core-1.16.0). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
This was referenced Jun 12, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
Omit histogram
_sumand_countin OpenMetrics when negative bucket thresholds are present.Merge requirement checklist
CHANGELOG.mdfiles updated for non-trivial changesChanges in public API reviewed (if applicable)